package kr.hkit.powerjava.chapter22.work2;

import java.util.*;

import kr.hkit.powerjava.chapter22.work.*;
import kr.hkit.powerjava.chapter22.work2.dao.*;
import kr.hkit.powerjava.chapter23.*;

public class TestMain {
	public static void main(String[] args) {
		ArrayList<Student> stdList = new ArrayList<>();
		StudentManagerImpl sm = new StudentManagerImpl(stdList);
		
		ArrayList<Department> dmList = new ArrayList<>();
		DepartmentManagerImpl dm = new DepartmentManagerImpl(dmList);
		
		
		//추가
		Student std1 = new Student(1, "김태희", 90, 90, 90);
		sm.addItem(std1);
		Student std2 = new Student(2, "제시카", 89, 79, 84);
		sm.addItem(std2);
		sm.addItem(new Student(3, "김주하", 80,80,80));
		sm.addItem(new Student(4, "이민정", 79,87,79));
		
		Department dpt1 = new Department(1, "컴공", 2);
		dm.addItem(dpt1);
		Department dpt2 = new Department(2, "사진",3);
		dm.addItem(dpt2);
		Department dpt3 = new Department(3, "미술",4);
		dm.addItem(dpt3);
		
		//삭제
/*		sm.delItem(std1);
		sm.delItem(std2);
		sm.delItem(std2);*/
		//검색
		Student searchItem = new Student(1, "김태희");
		String result = sm.searchItem(searchItem)? "존재" : "없음";
		System.out.println(searchItem.getStdNum()+ " : " + searchItem.getStdName()+ "="+result);
		
		//수정
		Student updateItem = new Student(1, "김태희", 91, 50, 15);
		sm.updateItem(updateItem);
		//출력
		sm.prnItems();
		dm.prnItems();
		
/*		System.out.println("총점순 정렬");
		Comparator<Student> totalCom = new Comparator<Student>() {
			
			@Override
			public int compare(Student o1, Student o2) {
				return (int)(o2.getTotal() - o1.getTotal());
			}
		};
		sm.prnItems(totalCom);*/
		
		System.out.println("학과명 정렬");
		Comparator<Department> de = new Comparator<Department>() {
			
			@Override
			public int compare(Department o1, Department o2) {
				return o1.getDeptName().hashCode() - o2.getDeptName().hashCode();	 
			}
		};
		dm.prnItems(de);
		
		
		sm.prnItems();
		System.out.println("이름순 정렬");
		Comparator<Student> com = new Comparator<Student>() {
			
			@Override
			public int compare(Department o1, Department o2) {
				// TODO Auto-generated method stub
				return o1.getStdName().hashCode() -o2.getStdName().hashCode();
			}
		};
		sm.prnItems(com);
		
		for(Student std : stdList){
			System.out.println(std);
		}
		System.out.println();
		
		Collections.shuffle(stdList);
		
		
		Student std = null;
		Iterator<Student> iterator = stdList.iterator();
		while(iterator.hasNext()){
			std = iterator.next();
			System.out.println(std);
		}
		
	}
	
}
